﻿using SqlSugar;
using System;
using System.Collections.Generic;
using xl.demo.models;
using xycn.DbService;

namespace DbTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            //创建数据库对象
            SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "server=47.115.18.214;port=4417; user id=rootdemo; password=rootdemo!2#4;database=demodb; pooling=false;CharSet=utf8;Allow Zero Datetime=True",//连接符字串
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
            });
            //添加Sql打印事件，开发中可以删掉这个代码
            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                foreach (var param in pars) sql = sql.Replace(param?.ParameterName, $"'{param.Value?.ToString()}'");
                Console.WriteLine(sql);
                //Log4Helper.Info("ExecSql:\r\n" + sql);
            };

            ////简单用例
            //var conModels = new List<IConditionalModel>();
            //conModels.Add(new ConditionalModel { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "1" });


            ////var x = db.Queryable<Members, Members2>((a, b) => true);
            ////x.QueryBuilder.EasyJoinInfos = null;
            ////x.AddJoinInfo("", "", "");
            ////x.Where();
            ////x.ToList();

            //var res = db.Queryable<Members, Members2, Members3>((a, b, c) => new JoinQueryInfos(
            //       JoinType.Left, a.KID == b.KID2,
            //       JoinType.Left, a.KID == c.KID3
            //       ))
            //       .Where((a, b) => b.KID2 == 1)
            //    .Select((a, b, c) => new MemberView
            //    {
            //        KID = SqlFunc.GetSelfAndAutoFill(a.KID),
            //        WxNickName = c.WxNickName3
            //    })

            //    .ToList();

            var num = "123";

            var res = db.Queryable<Members>().Where(p => p.KID == (string.IsNullOrWhiteSpace(num) ? 1 : 0)).ToList();

            //var res = db.Queryable<Members>().Where(p => string.IsNullOrWhiteSpace(num) ? p.KID < 50 : p.KID > 50).ToPageList(1, 10);

            Console.Write(res.Count.ToString());

            Console.ReadKey();
        }
    }
}
